// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV }) // 使用当前云环境

// 云函数入口函数
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext()
  
  try{
    const res = await cloud.openapi.subscribeMessage.send({
      touser: wxContext.OPENID,
      page: 'pages/home/home',
      lang: 'zh_CN',
      templateId: 'ZpzvwvEpbFKubxwL3bn3vXMxyL5l_II11d2spb_haSM',
      data:{
        character_string1:{
          value: event.guestNumber
        },
        name5: {
          value: event.guestName
        },
        thing6: {
          value: `${event.goodsTit[0]}*${event.goodsTit.length}套`
        },
        date2: {
          value: event.appointTime
        },
        phrase15: {
          value: '待拍摄'
        }
      }
    })
    return res
  }catch (err){
    return err
  }
}